package microcredit.gui.util;

import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import javax.swing.SwingWorker;

import microcredit.model.Report;
import microcredit.model.bo.BOReport;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

public class ReportWorker extends SwingWorker<JasperPrint, Object> {
	
	private final Report e;
	private final Map<String, Object> parameters;

	public ReportWorker(Report e, Map<String, Object> parameters) {
		this.e = e;
		this.parameters = parameters;
	}

	@Override
	protected JasperPrint doInBackground() throws Exception {
		return BOReport.create().run(e, parameters);
	}

	@Override
	protected void done() {
		try {
			JasperViewer.viewReport(get(), false, Locale.ENGLISH);
		} catch (InterruptedException e) {
			// do nothing on interrupted
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
